#/usr/bin/python
#-*-<coding=UTF-8>-*-

"""
本例为一个基本的wxPython GUI程序，包括菜单栏，工具栏，面板容器，状态栏
"""

import wx

class GuiMainFrame(wx.Frame):
    
    def __init__(self):
        wx.Frame.__init__(self,parent=None,id=-1,title="",pos=wx.DefaultPosition,size=wx.DefaultSize)
        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour("White")

        #menu bar
        menubar = wx.MenuBar()
        
        #File menu
        fileMenu = wx.Menu()
        fileMenu.Append(-1,"&Open","")
        menubar.Append(fileMenu,"&File")

        #Edit menu
        editMenu = wx.Menu()
        self.copy = editMenu.Append(-1,"&Copy","")
        self.color = editMenu.Append(-1,"Colo&r")
        #为什么要用frame绑定，为什么不用menu来绑定:
        #self.color.Bind(wx.EVT_MENU,self.OnColorChoice)         #编译不过，提示AttributeError: 'MenuItem' object has no attribute 'Bind'
        self.Bind(wx.EVT_MENU,self.OnColorChoice,self.color)
        menubar.Append(editMenu,"&Edit")

        #Help/About menu
        helpMenu = wx.Menu()
        helpMenu.Append(-1,"About","")
        menubar.Append(helpMenu,"&Help")
        
        #调用SetMenuBar，使其在框架中显示出来
        self.SetMenuBar(menubar)
        
        #添加工具栏,注意：用toolbar = wx.ToolBar()创建不行，会被其它的控件盖掉，这是为什么?
        #toolbar = wx.ToolBar(self)
        toolbar = self.CreateToolBar()
        tsize = (24,24)
        new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW,wx.ART_TOOLBAR,tsize)
        toolbar.AddSimpleTool(-1,new_bmp,"Long Help for 'New'")
        toolbar.Realize()
        
        #添加状态栏
        statusbar = self.CreateStatusBar()

    def OnColorChoice(self,event):
        colorDialog = wx.ColourDialog(self)
        colorDialog.GetColourData().SetChooseFull(True)
        if colorDialog.ShowModal() == wx.ID_OK:
            self.panel.SetBackgroundColour(colorDialog.GetColourData().GetColour())
        colorDialog.Destroy()

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = GuiMainFrame()
    frame.Show()
    app.MainLoop()
